<?php
use yii\helpers\Html;
use yii\helpers\Url;
/* @var $this yii\web\View */
$this->title = '登录';
?>
<section id="body_h">
		<div class='modular13'>
			<div class="modular12-con1from">
				<form action="#" method="post">
					<p class="oneelement greenborder"><input name="name" class="changeelement" placeholder="请输入用户名" type="text"></p>
					<p class="oneelement greenborder"><input name="password" class="changeelement" placeholder="请输入您的密码" type="password"></p>
					<p class="modular12-con1ts4 clearfix"><a class="float-left" href="<?= Url::to('signup');?>">立即注册</a><a class="float-right" href="<?= Url::to(['site/forgotloginpw']);?>">忘记密码</a></p>
					<p class="mould-2bot form-ok"><input class="form-okbtn b-f" type="submit" value="登录"></p>
				</form>
			</div>
		</div>
		<div class="footer-h"></div>
	</section>
	<section id="footer">
		<ul class="footer-nav clearfix">
		    <li class="current-bot">
		        <a href="<?= Url::to('main');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer1-on.png" alt="">
		            首页
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to('member');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer2.png" alt="">
		            我的账户
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to(['company/about']);?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer3.png" alt="">
		            关于我们
		        </a>
		    </li>
		</ul>
	</section>
	<p id="tip-error"><span>表单验证错误信息</span></p>
	
	<script>
	$(function($) {
	    var UA=window.navigator.userAgent;  //使用设备
	    var CLICK="click";
	    if(/ipad|iphone|android/.test(UA)){   //判断使用设备
	        CLICK="tap";
	    }
		$(".form-okbtn").click(function(event){
            event.preventDefault();
            var name=$("input[name='name']").val();
            	password=$("input[name='password']").val();
        	if(name == false){
				$('#tip-error span').html('姓名不能为空');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='name']").focus();
        	}else if(password == false){
				$('#tip-error span').html('密码不能为空');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='password']").focus();
        	}else{
				//$(this).parents("form").submit();
				$.ajax({
						type:'POST',
						url:'<?= Url::to(['site/signin']);?>',
						data:{name:name,password:password,'_csrf':'<?= yii::$app->request->getCsrfToken();?>'},
						success:function(data){
							var obj = eval('('+data+')');
							if(obj.status==0)
							{
								location.href='<?= Url::to(['site/member']);?>?sKey='+obj.obj.sKey;
							}
							else if(obj.msg=='session失效！')
							{
								$('#tip-error span').html('session失效！请重新登录');
						        $('#tip-error').show();
						        setTimeout(function(){$('#tip-error').fadeOut(500);location.href='<?= Url::to(['site/destroy']);?>';},1600);
							}
							else if(obj.msg=='不能重复登录！')
							{
								location.href='<?= Url::to(['site/member']);?>';
							}
							else
							{
								$('#tip-error span').html(obj.msg);
						        $('#tip-error').show();
						        setTimeout(function(){$('#tip-error').fadeOut(500);location.href='<?= Url::to(['site/destroy']);?>';},1600);
							}
						},
	                        error: function(xhr, type){
	                        	$('#tip-error span').html('登录失败！');
						        $('#tip-error').show();
						        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	                        }
				});
			}
		});
		$(".bodyA").hide();
	});
</script>